<#include "/oms/iframe/common/head_index.html" />
<div class="row">
	<div class="col-xs-12">
		<div class="box">
			<div class="box-header">
				<h3 class="box-title">用户会话监控</h3>
				<div class="box-tools pull-right">
					<@shiro.hasPermission name="system:monitor:session:delete">
						<a class="btn btn-sm btn-danger"  id="batchDelete" >删除</a>
					</@shiro.hasPermission>
					<@shiro.hasPermission name="system:monitor:session:export">
						<a class="btn btn-sm btn-primary"   title="导出" callback="paramReload()" data-body="确认要导出吗？" target="_self" method="GET" href='${request.contextPath}/system/monitor/session/export'>导出</a>
					</@shiro.hasPermission>
				</div>
			</div>
			<div class="box-body">
				<div class="clearfix">
					<form id="search-form" class="" >
						<div class="col-md-3">
							<div class="input-group date ">
								<div class="input-group-addon">
									<i class="fa fa-calendar"></i>
								</div>
								<input type="text"  class="form-control pull-right" name="beginCreatedTime" placeholder="选择开始时间...">
							</div>
						</div>
						<div class="col-md-3">
							<div class="input-group date ">
								<div class="input-group-addon">
									<i class="fa fa-calendar"></i>
								</div>
								<input type="text" class="form-control pull-right" name="endCreatedTime" placeholder="选择结束时间...">
							</div>
						</div>
						<div class="col-md-3">
							<div class="input-group">
								<span class="input-group-addon"><i class="fa fa-search"></i></span>
								<input type="text" class="form-control" name="username" placeholder="根据登录名搜索...">
							</div>
						</div>
						<div class="col-md-3">
							<button type="button" class="btn btn-primary btn-table-refresh">搜索</button>
						</div>
					</form>
				</div>
				<div class="clearfix" style="padding-top: 15px;">
					<table id="table-data" class="table table-bordered table-striped">
					</table>
				</div>
			</div>
		</div>
	</div>
</div>
<#include "/oms/iframe/common/setting_index.html" />
<#include "/oms/iframe/common/bottom_index.html" />
<script type="text/javascript">
$(function() {
   $dataTable = $("#table-data");

    $(".btn-table-refresh").on("click",function () {
        searchRefresh();
    });

    /**
	 * 批量删除
     */
    $("#batchDelete").on("click",function () {
        var obj = $dataTable.bootstrapTable('getSelections');
        var idArr =[];
        $.each(obj,function(index,item){
            idArr.push(item.id);
        });
        $.ajax({
            type: "delete",
            url: "${request.contextPath}/system/monitor/session/delete?ids="+idArr.join(','),
            dataType: "json",
            success: function(data){
                searchRefresh();
            }
        });
    });

	$.datetimepicker.setLocale('ch');
	//初始化时间选择器
	$('[name=beginStartTime]').datetimepicker({
		format:"Y/m/d 00:00:00",      //格式化日期
		timepicker:true,    //开启时间选项
		yearStart:2000,     //设置最小年份
		yearEnd:2050,        //设置最大年份
		todayButton:false    //关闭选择今天按钮
	});
	
	//初始化时间选择器
	$('[name=endStartTime]').datetimepicker({
		format:"Y/m/d 23:59:59",      //格式化日期
		timepicker:true,    //开启时间选项
		yearStart:2000,     //设置最小年份
		yearEnd:2050,        //设置最大年份
		todayButton:false    //关闭选择今天按钮
	});

    initDataGrid();

});

function searchRefresh(){
    $("#table-data").bootstrapTable('refresh');
}

function initDataGrid(){

    $dataTable.bootstrapTable({
        idField : "id",
        columns : [[
            {title: "", field: "checkbox" ,checkbox:true},
            {
                title: "序号",
				field: "index" ,
				width:10,
				formatter: function (value, row, index) {
                	return index+1;
                }
            },
            {title: "会话编号", field: "code" },
            {title: "登录名", field: "username" },
            {title: "IP地址", field: "ip" },
            {title: "浏览器类型", field: "browser" },
            {title: "登陆时间", field: "createdTime" ,formatter:dateFormat},
            {title: "注销时间", field: "logoutTime" ,formatter:dateFormat},
            {title: "操作", field: "operate", align: 'center',formatter: operateFormatter}
        ]],
        url : '${request.contextPath}/system/monitor/session/grid',
        queryParams: function(params){
            var searchForm = $("#search-form");
            var formData = searchForm.serializeObject();
            if(params.sort){
                formData["sort"]=params.sort;
                formData["order"]=params.order;
            }
            formData["offset"]=params.offset;
            formData["limit"]=params.limit;

            return formData;
        },
        responseHandler : function (res) {
            return {
                rows : res.rows,
                total : res.total
            }
        },
        search : false,
        searchOnEnterKey : false,
        sortName : 'createdTime',
        sortOrder : 'asc',
        pagination : true,
        sidePagination : 'server',
        pageSize: 10,
        pageList : [10,20, 40, 50, 100],
        showRefresh : true,
        showToggle : true
    });
}
function operateFormatter(value, row, index) {
    return [
        '<a class="btn btn-sm btn-info "  title="查看" target="modal" modal="lg" href="${request.contextPath}/system/monitor/session/view?id='+ row.id + '"  >'
        +'	<i class="glyphicon glyphicon-check"></i> '
        +'</a>  '
        +'<a class="btn btn-sm btn-danger"  title="删除" callback="searchRefresh()" data-body="确认要删除吗？" target="ajaxTodo" method="DELETE" href="${request.contextPath}/system/monitor/session/delete?ids='+ row.id + '">'
        +'	<i class="glyphicon glyphicon-remove"></i>'
        + '</a>&nbsp;'
    ].join('');
}
</script>